/**
 * 模拟的比赛数据
 * 用于前端开发和后端API参考
 */

// 格式化日期为"几月几日"格式
const formatDateStr = (date) => {
  const targetDate = new Date(date);
  const month = targetDate.getMonth() + 1;
  const day = targetDate.getDate();
  return `${month}月${day}日`;
};

// 获取今天及前后几天的日期
const getTodayAndNearbyDates = () => {
  const today = new Date();
  const yesterday = new Date(today);
  yesterday.setDate(today.getDate() - 1);
  const tomorrow = new Date(today);
  tomorrow.setDate(today.getDate() + 1);
  
  return {
    today,
    yesterday,
    tomorrow,
    dayBeforeYesterday: new Date(today.getFullYear(), today.getMonth(), today.getDate() - 2),
    dayAfterTomorrow: new Date(today.getFullYear(), today.getMonth(), today.getDate() + 2)
  };
};

// 模拟的比赛数据
export const getMatchesData = () => {
  const dates = getTodayAndNearbyDates();
  
  return [
    // 前天的比赛 - 单一推荐
    {
      id: 101,
      league: '英超联赛',
      round: '第27轮',
      date: dates.dayBeforeYesterday,
      dateTime: `${formatDateStr(dates.dayBeforeYesterday)} 20:00`,
      stadium: '安菲尔德球场',
      isCompleted: true,
      homeTeam: {
        name: '利物浦',
        shortName: 'LIV'
      },
      awayTeam: {
        name: '曼城',
        shortName: 'MCI'
      },
      score: {
        home: 1,
        away: 1
      },
      recommendations: ['home'],
      prediction: 'home',
      predictionResult: 'wrong'
    },
    
    // 昨天的比赛 - 双重推荐
    {
      id: 102,
      league: '西甲联赛',
      round: '第24轮',
      date: dates.yesterday,
      dateTime: `${formatDateStr(dates.yesterday)} 22:00`,
      stadium: '伯纳乌球场',
      isCompleted: true,
      homeTeam: {
        name: '皇家马德里',
        shortName: 'RMA'
      },
      awayTeam: {
        name: '巴塞罗那',
        shortName: 'BAR'
      },
      score: {
        home: 3,
        away: 2
      },
      recommendations: ['home', 'draw'],
      prediction: 'home',
      predictionResult: 'correct'
    },
    
    // 今天的比赛 - 单一推荐
    {
      id: 103,
      league: '英超联赛',
      round: '第28轮',
      date: dates.today,
      dateTime: `${formatDateStr(dates.today)} 20:30`,
      stadium: '斯坦福桥球场',
      isCompleted: false,
      homeTeam: {
        name: '切尔西',
        shortName: 'CHE'
      },
      awayTeam: {
        name: '阿森纳',
        shortName: 'ARS'
      },
      recommendations: ['home'],
      prediction: 'home'
    },
    
    // 明天的比赛 - 双重推荐
    {
      id: 104,
      league: '德甲联赛',
      round: '第25轮',
      date: dates.tomorrow,
      dateTime: `${formatDateStr(dates.tomorrow)} 21:30`,
      stadium: '安联球场',
      isCompleted: false,
      homeTeam: {
        name: '拜仁慕尼黑',
        shortName: 'BAY'
      },
      awayTeam: {
        name: '多特蒙德',
        shortName: 'DOR'
      },
      recommendations: ['home', 'away']
    },
    
    // 后天的比赛 - 无推荐
    {
      id: 105,
      league: '意甲联赛',
      round: '第26轮',
      date: dates.dayAfterTomorrow,
      dateTime: `${formatDateStr(dates.dayAfterTomorrow)} 19:45`,
      stadium: '圣西罗球场',
      isCompleted: false,
      homeTeam: {
        name: '国际米兰',
        shortName: 'INT'
      },
      awayTeam: {
        name: '尤文图斯',
        shortName: 'JUV'
      },
      recommendations: []
    }
  ];
};

// 模拟的冷门分析数据
export const getTrendingMatchesData = () => {
  const dates = getTodayAndNearbyDates();
  
  return [
    {
      id: 201,
      league: '德甲联赛',
      round: '第24轮',
      date: dates.tomorrow,
      dateTime: `${formatDateStr(dates.tomorrow)} 22:30`,
      stadium: '安联球场',
      isCompleted: false,
      isCold: true,
      homeTeam: {
        name: '拜仁慕尼黑',
        shortName: 'BAY'
      },
      awayTeam: {
        name: '波鸿',
        shortName: 'BOC'
      },
      stats: {
        home: 72,
        draw: 18,
        away: 10
      },
      analysis: '尽管拜仁实力占优，但近期双线作战体能消耗大，波鸿最近3次交锋1胜1平1负不落下风。'
    },
    {
      id: 202,
      league: '法甲联赛',
      date: dates.yesterday,
      dateTime: `${formatDateStr(dates.yesterday)} 21:00`,
      stadium: '里昂公园球场',
      isCompleted: true,
      isCold: true,
      homeTeam: {
        name: '里昂',
        shortName: 'LYO'
      },
      awayTeam: {
        name: '朗斯',
        shortName: 'LEN'
      },
      score: {
        home: 3,
        away: 2
      },
      predictionResult: 'correct',
      resultAnalysis: '里昂在落后2球的情况下实现逆转，验证了我们预测的冷门可能性。'
    }
  ];
};

/**
 * 模拟的API接口格式
 * 以下是后端API可能的返回格式示例
 */

// 获取指定日期的比赛列表
export const getMatchesByDateAPI = (date) => {
  return {
    code: 200,
    message: '获取成功',
    data: {
      matches: getMatchesData().filter(match => {
        // 过滤指定日期的比赛
        const matchDate = new Date(match.date);
        const targetDate = new Date(date);
        return (
          matchDate.getFullYear() === targetDate.getFullYear() &&
          matchDate.getMonth() === targetDate.getMonth() &&
          matchDate.getDate() === targetDate.getDate()
        );
      })
    }
  };
};

// 获取冷门分析列表
export const getTrendingMatchesAPI = (startDate, endDate) => {
  return {
    code: 200,
    message: '获取成功',
    data: {
      matches: getTrendingMatchesData().filter(match => {
        // 在指定日期范围内的冷门比赛
        const matchDate = new Date(match.date);
        const start = new Date(startDate);
        const end = new Date(endDate);
        return matchDate >= start && matchDate <= end;
      })
    }
  };
};

// 提交用户预测
export const submitPredictionAPI = (matchId, predictionType) => {
  return {
    code: 200,
    message: '提交成功',
    data: {
      match: {
        id: matchId,
        prediction: predictionType,
        updatedAt: new Date().toISOString()
      }
    }
  };
};

// 获取用户信息
export const getUserInfoAPI = () => {
  return {
    code: 200,
    message: '获取成功',
    data: {
      user: {
        id: 1001,
        name: '用户',
        email: 'user@example.com'
      }
    }
  };
};

export default {
  getMatchesData,
  getTrendingMatchesData,
  getMatchesByDateAPI,
  getTrendingMatchesAPI,
  submitPredictionAPI,
  getUserInfoAPI
}; 